﻿namespace NTLib.Pipe.UTest.Targets
{
    using NTLib.Pipe.Targets;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Threading;
    using NTLib.Pipe.Descriptors;

    public class TestTargetProvider : ITargetProvider
    {
        #region Fields

        private readonly IEnumerable<Type> _typies;
        private readonly string _signature;
        private Guid _guid;

        #endregion

        #region Methods

        /// <summary>
        /// Initializes a new instance of the <see cref="TestTargetProvider"/> class.
        /// </summary>
        /// <param name="signature">The signature.</param>
        /// <param name="typies">The typies.</param>
        public TestTargetProvider(string signature, params Type[] typies)
        {
            this._signature = signature;
            this._typies = typies;
            this._guid = Guid.NewGuid();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the information type managed.
        /// </summary>
        /// <value>
        /// The information type managed.
        /// </value>
        public IEnumerable<Type> InfoTypeManaged
        {
            get { return this._typies; }
        }

        /// <summary>
        /// Gets the identifier.
        /// </summary>
        public Guid Id
        {
            get { return this._guid; }
        }

        #endregion

        /// <summary>
        /// Gets a value indicating whether this instance is enabled.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is enabled; otherwise, <c>false</c>.
        /// </value>
        public bool IsEnabled
        {
            get { return true; }
        }

        public Task<IEnumerable<ITargetDescriptor>> LocateAsync<U>(U information, CancellationToken token = default(CancellationToken))
        {
            return Task.FromResult<IEnumerable<ITargetDescriptor>>(new[] { new TestTargetDesciption<U>(information, this._signature) });
        }
    }
}
